package com.mall.shopping.services;

import com.mall.shopping.IContentService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ContentConverter;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dto.NavListResponse;
import lombok.extern.log4j.Log4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Log4j
@Service
public class IContentServiceImpl implements IContentService {

    @Autowired
    ContentConverter converter;
    @Autowired
    PanelContentMapper panelContentMapper;

    @Override
    public NavListResponse queryNavList() {
        NavListResponse response = new NavListResponse();
        try {
            Example example = new Example(PanelContent.class);
            example.createCriteria().andEqualTo("panelId",0);
            example.setOrderByClause("sort_order asc");
            List<PanelContent> panelContents = panelContentMapper.selectByExample(example);
            response.setPannelContentDtos(converter.panelContents2Dto(panelContents));
            response.setCode(ShoppingRetCode.SUCCESS.getCode());
            response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        }catch (Exception e){
            response.setCode(ShoppingRetCode.SYSTEM_ERROR.getCode());
            response.setMsg(ShoppingRetCode.SYSTEM_ERROR.getMessage());
        }
        return response;
    }
}
